<template>
  <div>
    <el-card class="search-card">
      <basic-table-form
        ref="formData"
        :formColumns="formItemList"
        :dataSource="formData"
        :defaultExpandStatus="false"
        :handleSearchForm="handleQueryForm"
        @getFormData="getFormData"
      >
      </basic-table-form>
    </el-card>
    <el-card class="table-card">
      <basic-table
        :showSelectCol="false"
        :loading="tableInfo.loading"
        :columns="tableInfo.columns"
        :dataSource="tableInfo.list"
        :pagination="pagination"
        :tableHeight="460"
        @pageChange="handlePageChange"
        @pageSizeChange="handlePageSizeChange"
      >
        <div slot="content_context">
          <el-button
            v-if="showBtn('导出') && supplierExportConfig.returnViste"
            :loading="exportLoading"
            size="mini"
            type="primary"
            icon="el-icon-download"
            @click="handleExport"
            >导出</el-button
          >
        </div>
      </basic-table>
    </el-card>
  </div>
</template>
<script>
import BasicTableForm from '@/components/supplier/BasicForm';
import BasicTable from '@/components/supplier/BasicTable';
import { FORM_ITEM_LIST, TABLE_COLUMNS } from './constants';
import { getBtnsId } from '@/libs/btnsPermission';
import BasicPage from '@/mixins/supplier/basicPage';
import { queryNotInspectSupplierService, exportNotInspectSupplierService } from '@api/supplier/returnVisteManage';
import { isResponseSuccess } from '@/pages/supplier/utils/bizUtils';
import { createExcelByExport } from '@/utils/bizUtils';

export default {
  mixins: [ BasicPage ], // 分页数据及方法 表单基础方法
  components: {
    BasicTableForm,
    BasicTable,
  },
  data () {
    return {
      sendVisable: false,
      recordVisable: false,
      supplierData: {}, // 转派
      batchPushDownLoading: false,
      formItemList: FORM_ITEM_LIST,
      tableInfo: {
        list: [],
        selection: [],
        columns: TABLE_COLUMNS,
        loading: false
      },
      formData: {
        supplierCode: '',
        supplierName: '',
        supplierClassify: '',
        mainCategoryId: '',
      }
    };
  },
  created () {
    this.getTableData();
  },
  methods: {
    // 获取表格数据
    getTableData () {
      let data = {
        ...this.formData,
        ...this.pagination
      };
      sessionStorage.setItem('buttonId', getBtnsId('查询'));
      this.tableInfo.loading = true;
      queryNotInspectSupplierService(data).then((res) => {
        this.tableInfo.loading = false;
        if (isResponseSuccess(res)) {
          const { records, total } = res.result;
          this.tableInfo.list = records;
          this.pagination.total = total;
        }
      }).catch(() => {
        this.tableInfo.loading = false;
      });
    },
    // 导出
    handleExport () {
      this.exportLoading = true;
      exportNotInspectSupplierService(this.formData).then(res => {
        this.exportLoading = false;
        createExcelByExport({ excelTitle: '未考察供记录', res })
      }).catch(() => {
        this.exportLoading = false;
      })
    },
  }
};
</script>
